package com.xhlj.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xhlj.annotation.SystemLog;
import com.xhlj.entity.Activity;
import com.xhlj.service.ActivityService;
import com.xhlj.service.RegistrationsService;
import com.xhlj.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 *
 * @description 活动模块实现
 * @author Yzc
 * @create 2024/3/20
 **/

@RestController
@RequestMapping("activity")
public class ActivityController {

    @Resource
    private ActivityService activityService;

    @Resource
    private RegistrationsService registrationsService;

    //TODO:分页查询(可加标签条件)活动信息
    @GetMapping(value= "getActivityList")
    public Result getActivities(
            //分页参数默认为：第一页  页容量为10  默认返回所有会议
            @RequestParam(required = false,defaultValue = "1") Integer pageNo,
            @RequestParam(required = false,defaultValue = "10") Integer pageSize,
            @RequestParam(required = false,defaultValue = "all") String tag) {
        Page<Activity> page = new Page<>(pageNo,pageSize);
        IPage<Activity> ipage=activityService.getActivitiesByOpr(page,tag);
        return Result.ok(ipage);
    }

    //TODO:活动管理，对活动进行增、删 、改——也可通过若依框架加入活动表实现
    @SystemLog(title = "活动模块",content = "添加活动")
    @PostMapping()
    public Result addOrUpdateActivity(@RequestBody Activity activity){
        activityService.saveOrUpdate(activity);
        if (activity.getActivityId()==null)
            return Result.ok("活动添加成功");
        return Result.ok("活动修改成功");
    }
    @SystemLog(title = "活动模块",content = "删除活动")
    @DeleteMapping()
    public Result deleteActivityByIds(@RequestBody List<Integer> ids){
        activityService.removeBatchByIds(ids);
        return Result.ok("活动删除成功");
    }

    //TODO:用户点击按钮进行活动报名
    @SystemLog(title = "活动模块",content = "活动报名")
    @PostMapping("registration")
    private Result registerActivityById(
            @RequestHeader(defaultValue = "") String token,
            @RequestParam Integer id){
        return activityService.registerActivityById(id,token);
    }

    //TODO:活动统计模块：统计各个活动的报名人数，或可根据id得到指定活动的报名人数
    @GetMapping("dataList")
    private Result getActivityData(){
        return activityService.getActivitiesData();
    }

    //TODO:根据id查询指定活动的报名人数
    @GetMapping("data")
    private Result getActivityDataById(@RequestParam Integer id){
        return activityService.getActivityDataByid(id);
    }
}
